package com.zbkj.crmeb.merchant.admin.controller;


import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.github.pagehelper.PageInfo;
import com.zbkj.crmeb.chant.model.ChannelActivity;
import com.zbkj.crmeb.chant.request.ActivityListRequest;
import com.zbkj.crmeb.chant.request.ActivityProductsRequest;
import com.zbkj.crmeb.chant.request.AddActivityRequest;
import com.zbkj.crmeb.chant.service.ChannelActivityService;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 商户限时活动表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-05-30
 */
@RestController
@RequestMapping("/api/admin/mer/activity")
@Api(tags = "商户后台-限时活动")
public class MerChannelActivityController extends AdminBaseController {

    @Autowired
    ChannelActivityService channelActivityService;

    @ApiOperation(value = "限时活动分页列表")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<ChannelActivity>> getMerActivityList(ActivityListRequest request, HttpServletRequest servletRequest){
        PageInfo<ChannelActivity> pageInfo = channelActivityService.getMerActivityList(request,getMerId(servletRequest));
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "新增限时活动")
    @PostMapping(value = "/add")
    public CommonResult<String> addActivity(@RequestBody @Validated AddActivityRequest request, HttpServletRequest servletRequest){
        request.setMerId(getMerId(servletRequest));
        return channelActivityService.addActivity(request);
    }

    @ApiOperation(value = "删除限时活动")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<String> deleteActivity(@PathVariable("id") Integer id, HttpServletRequest servletRequest){
        // return CommonResult.success();
       return channelActivityService.deleteActivity(id,getMerId(servletRequest));
    }

    @ApiOperation(value = "查看商品")
    @GetMapping(value = "/products")
    public CommonResult<CommonPage<StoreProductResponse>> getProducts(@Validated ActivityProductsRequest request, HttpServletRequest servletRequest){
        request.setMerId(getMerId(servletRequest));
        PageInfo<StoreProductResponse> pageInfo = channelActivityService.getProducts(request);
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "小程序装修商品")
    @GetMapping(value = "/home/products")
    public CommonResult<CommonPage<StoreProductResponse>> getHomeProducts(@Validated ActivityProductsRequest request, HttpServletRequest servletRequest){
        request.setMerId(getMerId(servletRequest));
        PageInfo<StoreProductResponse> pageInfo = channelActivityService.getHomeProducts(request);
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "活动下拉列表")
    @GetMapping(value = "/list/drop")
    public CommonResult<List<ChannelActivity>> getMerActivityDropList(@ApiParam(value = "下拉条件 0全部  1未开始  2未开始、进行中", required = true) Integer type, HttpServletRequest servletRequest){
        List<ChannelActivity> list = channelActivityService.getMerActivityDropList(type,getMerId(servletRequest));
        return CommonResult.success(list);
    }

}

